﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
namespace BCMS.Ultilities.FinancialTextBox
{
    public partial class SerialInput : TextBox
    {
        public SerialInput()
        {
            InitializeComponent();
        }

        public SerialInput(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        public bool IsValid
        {
            get
            {
                bool retVal = true;
                try
                {
                    string strTxt = this.Text.Trim();
                    if (strTxt.IndexOf(",") <= 0 && strTxt.IndexOf("-") <= 0)
                    {
                        int _int = int.Parse(strTxt);
                    }
                    else
                    {
                        string[] strs = strTxt.Split(',');
                        foreach (string str in strs) {
                            string strTmp = str.Trim();
                            if (strTmp.IndexOf("-") > 0)
                            {
                                string[] tmps = strTmp.Split('-');
                                if (tmps.Length == 2)
                                {
                                    int _int1 = int.Parse(tmps[0].Trim());
                                    int _int2 = int.Parse(tmps[1].Trim());
                                    if (_int1 > _int2)
                                    {
                                        retVal = false;
                                        break;
                                    }
                                }
                                else
                                {
                                    retVal = false;
                                    break;
                                }
                            }
                            else
                            {
                                int _int = int.Parse(strTmp);
                            }
                        }
                    }
                }
                catch {
                    retVal = false;
                }

                return retVal;
            }
        }
    }
}
